package com.inossem.warehousestorage_inossem.activity.out_storage;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.inossem.loadandrefresh.pullableview.PullableListView;
import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.activity.base.BaseActivity;
import com.inossem.warehousestorage_inossem.activity.out_storage.extra.OutStorageExtra;
import com.inossem.warehousestorage_inossem.adapter.outStorage.PackageDetailSNListAdapter;
import com.inossem.warehousestorage_inossem.bean.outStorage.SNItemInfo;
import com.inossem.warehousestorage_inossem.utils.ActivityUtils;

import java.util.List;

//打包码中包含的序列号
public class PackageDetailActivity extends BaseActivity {

    private TextView title;

    private PullableListView packageDetailList;

    private PackageDetailSNListAdapter adapter;

    private List<SNItemInfo> mSNList;

    @Override
    protected void onCreateImpl(Bundle savedInstanceState) {
        setContentView(R.layout.activity_package_detail);
        initView(PackageDetailActivity.this);
    }

    @Override
    protected void onResumeImpl() {
        initData(PackageDetailActivity.this);
    }

    private void initView(Activity activity) {
        title = (TextView) activity.findViewById(R.id.headerTitle);
        packageDetailList = (PullableListView) activity.findViewById(R.id.packageDetailList);
    }

    private void initData(Activity activity) {
        title.setText("序列号列表");
        ActivityUtils.initBackAndFunction(activity, "返回", new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                finish();
            }
        });

        packageDetailList.setPullUpFlag(false);
        packageDetailList.setPullDownFlag(false);
        getExtra(activity);
        addSNItemListData(activity, mSNList, packageDetailList);
//        setmScanListener((String scanResult, int length) -> {
//            String type = QRCodeUtils.getQRCodeType(scanResult);
//            switch (type) {
//                case QRCodeConstant.TYPE_BATCH:
//                    adapter.addBatchRequest(activity, false, null, QRCodeUtils.DecryptQRCode(scanResult, QRCodeConstant.PARAMETER_BATCH_NUMBER));
//                    break;
//                case QRCodeConstant.TYPE_POSITION:
//                    adapter.addBatchRequest(activity, false, null, QRCodeUtils.DecryptQRCode(scanResult));
//                    break;
//            }
//        }, QRCodeConstant.TYPE_BATCH, QRCodeConstant.TYPE_POSITION);
    }

    private void getExtra(Activity activity) {
        mSNList = (List<SNItemInfo>) activity.getIntent().getSerializableExtra(OutStorageExtra.SN_LIST);
    }

    //填充数据
    private void addSNItemListData(Context context, List<SNItemInfo> snList, ListView listView) {
        adapter = new PackageDetailSNListAdapter(context, snList);
        listView.setAdapter(adapter);
    }

}
